package com.itboye.system.helper;

import java.lang.management.ManagementFactory;
import java.net.SocketException;
import java.net.UnknownHostException;

/**
 * ByUniqueIDHelper.java
 * Created on  2016/8/1 08:55
 * 版本       修改时间          作者      修改内容
 * V1.0.1    2016/8/1      hebidu    初始版本
 * <p>
 * Copyright (c) 2013 杭州博也网络科技有限公司 版权所有
 * HANGZHOU BOYE TECHNOLOGY CO.,LTD. All Rights Reserved.
 */
public class ByUniqueIDHelper {

    public static String generate(String salt,String seperate) throws SocketException, UnknownHostException {

        String hexNanoTime = ByDateHelper.getHexNanoTime();

        String localMac = ByLocalHostHelper.getLocalMac();
        String macHash =  Integer.toHexString(localMac.hashCode());
        // get name representing the running Java virtual machine.
        String name = ManagementFactory.getRuntimeMXBean().getName();
        // get pid
        String pid = name.split("@")[0];
        pid = Integer.toHexString(Integer.parseInt(pid));
        int rand = (int) (Math.random() * 10000);
        String strRand = Integer.toHexString (rand);

        return hexNanoTime + seperate + macHash + seperate + pid  + seperate + salt + seperate + strRand;
    }

}
